﻿using System.Collections.Generic;
using System.Drawing;

namespace Model
{
	public class Cell
	{
		private CellDefinition cellDefinition;
		public CellDefinition CellDefinition
		{
			get { return cellDefinition; }
			set { cellDefinition = value; }
		}

		private string name;
		public string Name
		{
			get { return name; }
			set { name = value; }
		}

		private Dictionary<string, string> attributes = new Dictionary<string, string>();
		public Dictionary<string, string> Attributes
		{
			get { return attributes; }
			set { attributes = value; }
		}

		private Point position;
		public Point Position
		{
			get { return position; }
			set { position = value; }
		}

		public Cell() { }

		public Cell(Cell cell, Point position)
		{
			this.attributes = new Dictionary<string, string>(cell.attributes);
			this.name = cell.name;
			this.position = position;
		}

		public Cell(CellDefinition cellDefinition, Point position)
		{
			this.name = cellDefinition.ZellTyp;
			this.position = position;
			init(cellDefinition);
		}

		public Cell(Cell cell)
		{
			this.attributes = new Dictionary<string, string>(cell.attributes);
			this.name = cell.name;
			this.position = cell.position;
		}

		public void init(CellDefinition cellDef)
		{
			cellDefinition = cellDef;
			this.name = cellDef.ZellTyp;
			attributes = new Dictionary<string, string>();

			foreach (Attribut tmpAttr in cellDef.Attribute)
			{
				if (tmpAttr is StringAttribut)
					this.attributes.Add(tmpAttr.Name, "");

				if (tmpAttr is NumberAttribut)
					this.attributes.Add(tmpAttr.Name, "0");
			}
		}

		public override string ToString()
		{
			return name;
		}
	}
}
